package com.tttshaoqi.server.controller;

import com.tttshaoqi.annotation.Log;
import com.tttshaoqi.common.result.PageResult;
import com.tttshaoqi.common.result.Result;
import com.tttshaoqi.pojo.entity.Flight;
import com.tttshaoqi.server.service.FlightService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/flight")
@Slf4j
public class FlightController {

    @Autowired
    private FlightService flightService;

    /**
     * 分页查询航班信息
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/page")
    public Result goodList(String airlineName,String departureCity,String arrivalCity,
                           @RequestParam(defaultValue = "1") Integer page,
                           @RequestParam(defaultValue = "5") Integer pageSize){
        log.info("查询商品列表：{},{},{},{}",airlineName,page,pageSize,departureCity,arrivalCity);
        PageResult pageResult = flightService.page(airlineName,page,pageSize,departureCity,arrivalCity);
        return Result.success(pageResult);
    }

    /**
     * 修改航班信息
     */
    @Log
    @PutMapping()
    public Result update(@RequestBody Flight flight){
        log.info("修改航班信息:{}",flight);
        flightService.update(flight);
        return Result.success();
    }

    /**
     * 添加航班信息
     */
    @Log
    @PostMapping()
    public Result addFlight(@RequestBody Flight flight){
        log.info("添加航班信息：{}",flight);
        flightService.add(flight);
        return Result.success();
    }

    /**
     * 删除航班信息
     */
    @Log
    @DeleteMapping()
    public Result delete(Integer id){
        log.info("删除航班信息：{}",id);

        return flightService.delete(id);
    }
}
